/*
 * @Description:
 * @Version: 1.0
 * @Author: liguansheng
 * @Date: 2022-08-18 11:16:06
 * @LastEditors: liguansheng
 * @LastEditTime: 2022-08-26 13:06:51
 */
import axios from '@/utils/request'

import { IPageResult } from './types/base'
import {
  ICreateIdentityResourceData,
  IIdentityResource,
  IUpdateIdentityResourceData,
} from './types/identityResources'

// 创建标准身份资源
export function createStandardResources() {
  return axios({
    url: '/api/identity-server/identity-resources/create-standard-resources',
    method: 'post',
  })
}

// 新增身份资源
export function createIdentityResources(data: ICreateIdentityResourceData) {
  return axios({
    url: '/api/identity-server/identity-resources',
    method: 'post',
    data,
  })
}

// 删除身份资源
export function deleteIdentityResource(id: string) {
  return axios({
    url: '/api/identity-server/identity-resources',
    method: 'delete',
    params: {
      id,
    },
  })
}

// 修改身份资源
export function updateIdentityResource(
  id: string,
  data: IUpdateIdentityResourceData,
) {
  return axios({
    url: `/api/identity-server/identity-resources/${id}`,
    method: 'put',
    data,
  })
}

// 获取身份资源分页列表
export function pagedIdentityResources(
  currentPage = 1,
  take = 10,
  filter: string,
) {
  return axios<IPageResult<IIdentityResource>>({
    url: '/api/identity-server/identity-resources',
    method: 'get',
    params: Object.assign({
      skipCount: take * (currentPage - 1),
      maxResultCount: take,
      filter,
    }),
  })
}

// 获取身份资源详情
export function getIdentityResource(id: string) {
  return axios<IIdentityResource>({
    url: `/api/identity-server/identity-resources/${id}`,
    method: 'get',
  })
}
// 获取所有身份资源
export function getAllIdentityResources() {
  return axios<IIdentityResource[]>({
    url: '/api/identity-server/identity-resources/all',
    method: 'get',
  })
}
